package com.connectDB;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.beans.PropertyVetoException;

import com.HttpClient.InitPeoPle;
import com.mchange.v2.c3p0.ComboPooledDataSource;

public class DBPool {
	private static DBPool dbPool;
	private ComboPooledDataSource dataSource;

	static {
		dbPool = new DBPool();
	}

	public DBPool() {
		String url ="jdbc:oracle:thin:@10.86.88.89:1521/GAP";
		String userName = "gap";
		String password ="geelygap";
		try {
			dataSource = new ComboPooledDataSource();
			dataSource.setUser(userName);
			dataSource.setPassword(password);
			dataSource.setJdbcUrl(url);
			dataSource.setDriverClass("oracle.jdbc.driver.OracleDriver"); // orcl
			// dataSource.setDriverClass("com.ibm.db2.jcc.DB2Driver"); //db2
			dataSource.setInitialPoolSize(2);
			dataSource.setMinPoolSize(1);
			dataSource.setMaxPoolSize(30);
			dataSource.setMaxStatements(50);
			dataSource.setMaxIdleTime(60);
		} catch (PropertyVetoException e) {
			throw new RuntimeException(e);
		}
	}

	public final static DBPool getInstance() {
		return dbPool;
	}

	public final Connection getConnection() {
		try {
			return dataSource.getConnection();
		} catch (SQLException e) {
			System.out.println("����ʧ��");
			e.printStackTrace();
			throw new RuntimeException("�޷������Դ��ȡ���� ", e);

		}
	}

	
	
	
	public static void main(String[] args) {
		Connection con = null;
		try {
			con = DBPool.getInstance().getConnection();
			String sql = "SELECT * FROM gap_ca_user  where (istx!=1  or istx  is  null)   and isdeleted=0     order by userid desc "; 
			PreparedStatement ps = con.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				String myid = rs.getString("userid");
				String myname = rs.getString("username");
				InitPeoPle in=new InitPeoPle();
				in.initPeo(myid, myname);
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (con != null)
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
		}
	}
}
